<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

class LoginController extends  HomeController {
	//登录
    public function index(){
        $requestdata = file_get_contents("php://input");
        $paramData = json_decode($requestdata, true);

        $model = D("User");
        if(empty($paramData['login_name']) || empty($paramData['password'])) $this->throw_exception("账号密码都不能为空");

        $user_info = $model->get_user_info(['login_name' => $paramData['login_name']]);
        if(empty($user_info)) $this->throw_exception('该登录账号不存在');


        if($user_info['password'] != md5($paramData['password'])) $this->throw_exception('密码错误,请重新输入');
        if($user_info['status'] != 1) $this->throw_exception('该账号不允许登录');

        $data = [
            'token'        => $this->getLoginToken($user_info),
            'launch_time'  => date('Y-m-d H:i:s',time()+3600*24*365),
            'user_id'      => $user_info['id'],
            'user_name'    => $user_info['user_name'],
            'login_name'   => $user_info['login_name']
        ];

        $returnData = [
            'code' => 200,
            'data' => $data
        ];
        echo json_encode($returnData);
    }





    //上传图片
    public function upload_file(){
        $this->is_login($_POST['token']);      //判断是否登录
        $result = $this->upload();
        echo json_encode($result);
    }

}